package com.juntuo.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.juntuo.Enums.Constants;
import com.juntuo.entity.Company;
import com.juntuo.entity.Device;
import com.juntuo.entity.DeviceHistory;
import com.juntuo.entity.User;
import com.juntuo.service.CompanyService;
import com.juntuo.service.DeviceHistoryService;
import com.juntuo.service.DeviceService;
import com.juntuo.shiro.ShiroUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 对片区 街道 泊位等进行管理
 * @author chen xj
 * @create 2017/03/03 11:04
 */
@Controller
@RequestMapping("/device/history")
public class DeviceHistoryController {

    @Autowired
    private DeviceHistoryService deviceHistoryService;
    @Autowired
    private DeviceService deviceService;

    @RequestMapping("/index")
    public String toIndex(){
        return "/history/index";
    }


//    @RequestMapping("/page")
//    @ResponseBody
//    public PageInfo<Map<String,Object>> getPage(int pageNumber, int pageSize, String name){
//            return deviceHistoryService.findPagedDeviceHistory(pageNumber,pageSize,name);
//    }


    @RequestMapping("/{name}")
    public String toDetail(Model model,@PathVariable String name){
        model.addAttribute("name",name);
        return "/history/detail";
    }

    @RequestMapping("/page")
    @ResponseBody
    public PageInfo<Map<String,Object>> getPage(int pageNumber, int pageSize,String name){

        return deviceHistoryService.findPagedDeviceHistory(pageNumber,pageSize,name);
    }

    @RequestMapping("/dynamic/{deviceName}")
    public String toDynamic(Model model,@PathVariable String deviceName){
        Device device = new Device();
        device.setName(deviceName);
        device=deviceService.selectOne(device);
        model.addAttribute("deviceId",device.getDeviceId());
        model.addAttribute("deviceName",deviceName);
        return "/history/dynamic";
    }



}
